'''
Created on Feb 5, 2013

@author: nzhao
'''
from traits.api import Instance, Float

from phy.general.Constant import GammaUnit_B
from math_qm.vector import vector
from phy.spin.SingleSpin import SingleSpin

b0 = vector()

class SingleSpinInteraction(SingleSpin):
    local_field = Instance(vector)
    crystal_field = Float()
    
    def __init__(self, element='NV', spin_type='Central', spin_mark='None', position=[0., 0., 0.], x=0.0, y=0.0, z=0.0, b = b0, d = 0.0):
        if position is not None:
            xval, yval, zval = position
        else:
            xval, yval, zval = x, y, z
            
        SingleSpin.__init__(self, element=element, spin_type=spin_type, spin_mark=spin_mark, x=xval, y=yval, z=zval)
        
        self.local_field = b
        self.crystal_field = d
    
    def zeeman(self):
        return self.spin_relative_Gamma * GammaUnit_B * self.local_field.xyz

    def set_local_field(self, b):
        self.local_field = b
    def set_crystal_field(self,d):
        self.crystal_field = d
    def get_local_field(self):
        return self.local_field.xyz
        
if __name__ == '__main__':
    s = SingleSpinInteraction(element = 'C13', spin_type = 'Bath', spin_mark='None', x = 0.0, y = 0.0, z = 0.0)
    print s.spin_type, s.crystal_field